package com.feige.controller;


import com.feige.pojo.SignIn;
import com.feige.service.SignInService;
import com.feige.utils.device.DeviceUtil;
import com.feige.utils.device.IpUtil;
import com.feige.result.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.mobile.device.Device;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 签到表 前端控制器
 * </p>
 *
 * @author feige
 * @since 2020-11-20
 */
@Api(tags = "签到控制器")
@RestController
@RequestMapping("/sign/sign-in")
public class SignInController {

    @Resource
    private SignInService signInService;



    @ApiOperation("保存签到信息")
    @PostMapping("/save")
    public AjaxResult save(HttpServletRequest request, Device device, @RequestBody SignIn signIn){
        signIn.setSignIp(IpUtil.getIpAddr(request));
        signIn.setSignDevice(DeviceUtil.getDevice(device));
        return signInService.saveSignIn(signIn);
    }

    @ApiOperation("获取签到详情")
    @GetMapping("/{courseId}/{signTaskId}/{bt}")
    public AjaxResult get(@PathVariable String courseId, @PathVariable String signTaskId,@PathVariable Long bt){
        return signInService.getSignDetail(courseId,signTaskId,bt);
    }

}

